from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views

# 创建路由器
router = DefaultRouter()
router.register(r'work-orders', views.SQLRequestViewSet, basename='work-orders')

urlpatterns = [
    # 包含路由器的URL
    path('', include(router.urls)),

    # 数据库实例管理
    path('database-instances/', views.database_instances, name='database_instances'),
    path('database-instances/<int:instance_id>/', views.delete_database_instance, name='delete_database_instance'),
    path('database-instances/<int:instance_id>/test-connection/', views.test_database_connection, name='test_database_connection'),
    path('database-instances/<int:instance_id>/schema/', views.get_database_schema, name='get_database_schema'),
    path('database-instances/<int:instance_id>/databases/', views.get_database_list, name='get_database_list'),
    path('database-instances/<int:instance_id>/databases/<str:database>/tables/', views.get_table_list, name='get_table_list'),
    path('database-instances/<int:instance_id>/databases/<str:database>/tables/<str:table>/structure/', views.get_table_structure, name='get_table_structure'),

    # 测试连接（不保存实例）
    path('test-connection/', views.test_connection_params, name='test_connection_params'),

    # SQL查询
    path('execute-query/', views.execute_query, name='execute_query'),
    path('analyze-sql/', views.analyze_sql, name='analyze_sql'),

    # 工单相关
    path('admin-users/', views.get_admin_users, name='get_admin_users'),

    # SQL变更请求（保留旧的API）
    path('requests/', views.sql_requests, name='sql_requests'),
    path('requests/<int:request_id>/review/', views.review_sql_request, name='review_sql_request'),

    # 我的工单（保留旧的API）
    path('my-tickets/', views.my_tickets, name='my_tickets'),
    path('my-tickets/<int:ticket_id>/', views.my_ticket_detail, name='my_ticket_detail'),
    path('my-tickets/<int:ticket_id>/withdraw/', views.withdraw_ticket, name='withdraw_ticket'),

    # SQL历史
    path('history/', views.sql_history, name='sql_history'),
]
